package com.situ.mall.controller.back;

import java.util.Arrays;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.situ.mall.entity.User;
import com.situ.mall.entity.Category;
import com.situ.mall.entity.Result;
import com.situ.mall.service.ICategoryService;
import com.situ.mall.service.IUserService;

@Controller
@RequestMapping("/user")
public class UserController {
	
	@Autowired
	private IUserService userService;


//测试
	@RequestMapping("/selectAll.action")
	@ResponseBody
	public List<User> selectAll() {
		System.out.println("UserController.selectAll()");
		return userService.selectAll();
	}
	
//后台
// 0. index.jsp点一下   跳转到这里    再转发到   User_list。jsp
	
	@RequestMapping("/getUserListJsp.action")
	public String getUserListJsp() {
		System.out.println("UserController.getUserListJsp()");
		return "user_list";
	}
	
// 1.查询 每页信息     返回Result到	User_list.jsp
	@RequestMapping("/selectByPage.action")
	@ResponseBody
	public Result selectByPage(@RequestParam(defaultValue = "1") Integer page,
			@RequestParam(defaultValue = "10") Integer limit) {
		System.out.println("UserController.selectByPage()");
		
		return userService.selectByPage(page, limit);
	}
	
	
// 2.批量删除
	@RequestMapping("/deleteAll.action")
	@ResponseBody
	public Result deleteAll(Integer[] ids) {
		System.out.println("UserController.deleteAll()");
		return userService.deleteAll(ids);
	}
	
// 3.删除
	@RequestMapping("/deleteById.action")
	@ResponseBody
	public Result deleteById(Integer id) {
		System.out.println("UserController.deleteById()");
		return userService.deleteById(id);
	}

//4.添加
	//4.1.转发 到 insert.jsp
	@RequestMapping("/getUserInsertJsp.action")
	public String getProductInsertPage() {
		System.out.println("UserController.getProductInsertJsp()");

		return "user_insert";
	}
	
	//4.2添加数据到数据库
	@RequestMapping("/insert.action")
	@ResponseBody
	public Result insert(User user) {
		System.out.println("UserController.insert()");
		System.out.println(user);
		
		return userService.insert(user);
	}
	

	
}
